<template>
<div class="staff">
<div class="check4" style="background-color: #ffffff">
    <div class="searchArea">
        <form action="###" class="searchForm">
          <input
            type="text"
            placeholder="输入关键词"
            v-model="keywords"
          />
          <button
            class="sui-btn btn-xlarge btn-danger"
            type="button"
            @click="goSearch"
          >
            搜索
          </button>
          <el-button @click="delay" style="margin-left:10px;">取消</el-button>
        </form>
    </div>
    <el-table
      class="table3"
      :data="tableData"
      style="width: 100%"
      max-height="500"
    >
      <el-table-column fixed prop="userName" label="员工账号" width="220">
      </el-table-column>
      <el-table-column prop="employeesName" label="员工姓名" width="220">
      </el-table-column>
      <el-table-column prop="employeePosition" label="员工职位/权限" width="220">
      </el-table-column>
      <el-table-column prop="employeeContact" label="联系方式" width="220">
      </el-table-column>
    </el-table>
    <div class="block">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="this.page.currentPage"
        :page-sizes="[10, 20, 30, 40,50]"
        :page-size="this.page.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="this.page.total"
      >
      </el-pagination>
    </div>
  </div>
  </div>
</template>

<script>
import axios from '../../../axios'
export default {
  name: 'check',
  data () {
    return {
      tableData: [{}],
      keywords: '',
      searchBoolean: false,
      page: {
        // 当前页码
        currentPage: 1,
        // 每页条数
        pageSize: 10,
        // 数据总条数
        total: ''
      }
    }
  },
  methods: {
    delay () {
      this.keywords = '',

      axios({
        url: '/employee/query/QueryByBlurry',
        method: 'POST',
        data:
                {
                  blurryString: this.keywords,
                  pageSize: this.page.pageSize,
                  currentPage: this.page.currentPage
                },
        headers: {
          'Content-Type': 'application/x-www-form-urlencoded'
        }

      }).then(res => {
        // 拿到后端分页数据
        this.tableData = res.data.data.records
        this.searchBoolean = true
        // 拿到后端数据总条数
        this.page.total = parseInt(res.data.data.total)
      })
    },
    // 模糊查询分页调用共同函数
    serarch () {
      axios({
        url: '/employee/query/QueryByBlurry',
        method: 'post',
       data:
                {
                  blurryString: this.keywords,
                  pageSize: this.page.pageSize,
                  currentPage: this.page.currentPage
                },
  

      }).then(res => {
        // 拿到后端分页数据
        this.tableData = res.data.data.records
        this.searchBoolean = true
        // 拿到后端数据总条数
        this.page.total = parseInt(res.data.data.total)
      })
    },
    // 模糊查询
    goSearch () {
      this.page.currentPage = 1,
      this.serarch()
    },
    // 条数选择
    // 条数选择
    handleSizeChange (val) {
      this.page.pageSize = val
      this.page.currentPage = 1
      if (this.searchBoolean) {
        // 如果执行了模糊查询则调用该接口分页
        this.serarch()
        return
      }
      axios({
        url: '/employee/query',
        method: 'get',
        // 上传page参数,让后端进行分页
        params: this.page
      }).then(res => {
        // 拿到后端分页数据
        this.tableData = res.data.data.records
        // 拿到后端数据总条数
        this.page.total = parseInt(res.data.data.total)
      })
    },
    // 下一页
    handleCurrentChange (val) {
      this.page.currentPage = val
      console.log(`当前页: ${val}`)
      if (this.searchBoolean) {
        // 如果执行了模糊查询则调用该接口分页
        this.serarch()
        return
      }
      axios({
        url: '/employee/query',
        method: 'get',
        // 需要想办法传入page对象
        params: this.page
      }).then(res => {
        this.tableData = res.data.data.records
      }).catch(err => {
        this.$alert(err.response.data.msg, '请联系管理员', {
          confirmButtonText: '确定',
          callback: action => {

          }
        })
      })
    }

  },
  created () {
    // 页面刷新时重置搜索框和按键状态
    this.keywords = '',
    this.searchBoolean = false,
    console.log(this.page)
    axios({
      url: '/employee/query',
      method: 'get',
      // 需要想办法传入page对象
      params: this.page
    }).then(res => {
      this.tableData = res.data.data.records
      this.page.total = parseInt(res.data.data.total)
      console.log(this.page.total)
    }).catch(err => {
      console.log(err.response)
      this.$alert(err.response.data.msg, '请联系管理员', {
        confirmButtonText: '确定',
        callback: action => {

        }
      })
    })
  }
}
</script>
<style lang="less" >
 .staff{
    width: 1200px;
    margin: 0 auto;
    display: flex;
    position: relative;
.check4 {
height: 700px;
  overflow: hidden;
  margin-top: 30px;
  margin-left: 50px;
    .cell
{
  font-weight: bold;
  font-size: 20px;
  color: rgb(61, 59, 59);
}
.el-pagination{
  .el-pagination__total{
  font-weight: bold;
  font-size: 20px;
  color: rgb(61, 59, 59);
}
.el-input__inner{
  font-weight: bold;
  font-size: 20px;
  color: rgb(61, 59, 59);
}
.button{
  font-weight: bold;
  font-size: 20px;
  color:rgb(61, 59, 59);
}
.el-pager
.number{
  font-weight: bold;
  font-size: 20px;

}
.el-pagination__jump{
  font-weight: bold;
  font-size: 20px;
  color:rgb(61, 59, 59);
}
}
    .searchArea {
      float: left;
      margin-top: 30px;
      margin-right: 100px;

      .searchForm {
        overflow: hidden;
        margin-right: 0px;

        input {
          box-sizing: border-box;
          width: 300px;
          height: 38px;
          padding: 0px 4px;
          border: 2px solid rgb(8, 138, 8);
          float: left;

          &:focus {
            outline: none;
          }
        }

        button {
          height: 38px;
          width: 68px;
          background-color: #0f778a;
          border: none;
          color: #fff;
          float: left;
          cursor: pointer;

          &:focus {
            outline: none;
          }
        }
      }

    }
  .table3{
           width: 950px!important;
       }

}
 }

</style>
